package src.CodeTopSecondPractice;

import java.util.HashMap;

public class _3 {
    public int lengthOfLongestSubstring(String s) {
        if (s.length() == 0 || s.length() == 1)
            return s.length();
        int length = 1;
        HashMap<Character, Integer> map = new HashMap<>();
        for (int left = 0, right = 0 ; right < s.length() ; right++) {
            if (map.containsKey(s.charAt(right))) {
                left = Math.max(left, map.get(s.charAt(right)) + 1);
            }
            length= Math.max(length, right - left + 1);
            map.put(s.charAt(right), right);
        }
        return length;
    }
}
